<template>
  <PageWrapper dense contentFullHeight fixedHeight contentClass="flex">
    <BasicTable @register="registerTable">
      <template #toolbar>
        <!--        <a-button type="primary" @click="handleCreate">新增分类</a-button>-->
      </template>
      <template #action="{ record }">
        <TableAction
          :actions="[
            {
              label: '查看',
              onClick: handleLookModal.bind(null, record),
            },
          ]"
        />
      </template>
    </BasicTable>
    <OrderModal @register="registerLookModal" @success="handleLookModal" />
  </PageWrapper>
</template>

<script lang="ts">
  import { defineComponent } from 'vue';
  import { BasicTable, TableAction, useTable } from '/@/components/Table';
  import { PageWrapper } from '/@/components/Page';
  import { columns, searchFormSchema } from './practice.data';
  import { getListPage } from '/@/api/order/cuisineOrder';
  import { useModal } from '/@/components/Modal';
  import OrderModal from './modules/OrderModal.vue';

  export default defineComponent({
    name: 'Index',
    components: { BasicTable, PageWrapper, TableAction, OrderModal },
    setup() {
      function handleSuccess() {
        reload();
      }

      const [registerTable, { reload }] = useTable({
        title: '订单列表',
        rowKey: 'id',
        api: getListPage,
        columns,
        dataSource: [],
        useSearchForm: false,
        /*  formConfig: {
          labelWidth: 120,
          schemas: searchFormSchema,
        },*/
        showTableSetting: true,
        bordered: true,
        actionColumn: {
          width: 120,
          title: '操作',
          dataIndex: 'action',
          slots: { customRender: 'action' },
        },
      });

      const [registerLookModal, { openModal }] = useModal();
      function handleLookModal(record: Recordable) {
        console.log(record);
        openModal(true, {
          record,
          isUpdate: true,
        });
      }

      return {
        registerTable,
        handleSuccess,
        registerLookModal,
        handleLookModal,
      };
    },
  });
</script>

<style scoped></style>
